package me.boot.web.common.template.impl;

import me.base.utils.ReflectUtil;
import me.boot.db.mybatis.template.SuperService;
import me.boot.db.mybatis.template.entity.Entity;
import me.boot.web.common.template.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;

public abstract class BaseControllerImpl<
        ID extends Serializable,
        PO extends Entity<ID>,
        S extends SuperService<ID, PO>>
        implements BaseController<ID, PO, S> {

    @Autowired
    protected S service;
    protected Class<PO> entityClass = null;

    @Override
    public Class<PO> getPoClass() {
        if (entityClass == null) {
            this.entityClass = ReflectUtil.getGenericType(this.getClass(), 1);
        }
        return entityClass;
    }

    @Override
    public S getService() {
        return service;
    }
}
